<?php
namespace app\admin\controller;
use app\model\ImageImport as ImageImportModel;
use think\Db;


class ImageImport extends Base
{
    public function __construct(){
        $model = new ImageImportModel();
        $this->model = $model;
        parent::__construct();
        
        $page_info = $this->page_info;
        $page_info['title'] = '分类';

        $this->assign([
            'model'=>$this->model,
            'page_info'=>$page_info
        ]);
    }

    public function assignFields(){
        $model = $this->model;

        $fields = [
            'bos_path'=>['name'=>'BOS目录路径','type'=>'text'],
        ];
        $valids = createPageValid($fields);
        $this->assign([
            'fields'=>$fields,
            'valids'=>$valids
        ]);

    }

    public function assignSearchs(){
        // $model = $this->model;
        // $search_params = [
        //     [
        //         ['key'=>'name','name'=>'名称','type'=>'text'],
        //     ]
        // ];
        // $this->assign([
        //     'search_params'=>$search_params
        // ]);
    }

    public function index(){
        $model = $this->model;
        $map_params = [
            ['key'=>'name','type'=>'like'],
        ];
        $map = getSearchParam($map_params);

        $page_param = [
            'page'=>input('page',1),
            'list_rows'=>input('page_size',20)
        ];
        // 显示筛选
        $this->assignSearchs();

        $list = $model->where($map)->order('id','desc')->paginate($page_param);
        $page = $list->render();
        $list = $list->toarray();
        foreach ($list['data'] as $k => $vo) {
            
        }
        return view('index', [
            'list'=>$list,
            'page'=>$page
        ]);
    }

    public function add(){
        if (request()->isPost()) {
            $fields = [
                'must'=>['bos_path'],
            ];
            $save_data = paramFilter(request()->param(),$fields);
            if (!empty($save_data['error_msg'])) {
                $this->error($save_data['error_msg']);
            }
        }

        return parent::saveData($save_data);
    }

    // public function edit(){
    //     $id = input('id');
    //     if (empty($id)) { $this->error('id不能为空'); }
        
    //     $model = $this->model;
    //     if (request()->isPost()) {
    //         $fields = [
    //             'must'=>['name'],
    //             'nomust'=>['image','description','sort']
    //         ];
    //         $save_data = paramFilter(request()->param(),$fields);
    //         if (!empty($save_data['error_msg'])) {
    //             $this->error($save_data['error_msg']);
    //         }
    //     }

    //     return parent::updateData($id,$save_data);
    // }




   
}
